<?php
namespace app\student\controller;

use app\common\model\Base;
use app\student\model\StudentExamManager;

class Exam extends Base
{
    const SUCCESS_EXAM = "成功报名考试";
    private $studentExamManager;

    public function __construct()
    {
        parent::__construct();
        $this->studentExamManager = new StudentExamManager();
    }

    /**
     *
     * @api {get} /exam 学生可报名的场次
     * @apiDescription 获取学生的可报名的场次
     * @apiGroup student
     *
     * @apiSuccess {String} code 0 表示失败 1 表示成功.
     * @apiSuccess {String} msg 返回报名场次.
     * @apiSuccessExample {json} Success-Response:
     *     {
     *       "code": "1",
     *       "msg": [{"返回报名场次"}]
     *     }
     */
    public function index(){
        //echo "123";
        echoJson(1,$this->studentExamManager->getExamScheduleByStatus(StudentExamManager::ACCEPT_EXAM));
    }

    /**
     *
     * @api {get} /exam/:id 获取学生的考试信息
     * @apiDescription 学生账号登录
     * @apiGroup student
     * @apiParam {string} :id 学号
     *
     *
     * @apiSuccess {String} code 0 表示失败 1 表示成功.
     * @apiSuccess {String} msg 获取学生的考试信息
     * @apiSuccessExample {json} Success-Response:
     *     {
     *       "code": "1",
     *       "msg": "获取学生的考试信息"
     *     }
     */
    public function read($id){
        echoJson(1, $this->studentExamManager->getExamRegisterByStudentId($id));
    }

    /**
     *
     * @api {put} /exam/:id 申请计算机文化考试
     * @apiDescription 申请计算机文化考试
     * @apiGroup student
     * @apiParam {string} :id 学号
     * @apiParam {string} exam 考试号
     *
     *@apiParamExample {json} Request-Example:
     *     {
     *       "exam": 考试号，
     *     }
     *
     * @apiSuccess {String} code 0 表示失败 1 表示成功.
     * @apiSuccess {String} msg 加入考试成功
     * @apiSuccessExample {json} Success-Response:
     *     {
     *       "code": "1",
     *       "msg": "加入考试成功"
     *     }
     */
    public function update($id){
        $exam = $_GET["exam"];
        //echoJson(1, $this->studentExamManager->createExamRegisterByStudentId($id, $exam));
        if($this->studentExamManager->createExamRegisterByStudentId($id, $exam)){
            echoJson(1, self::SUCCESS_EXAM);
        }
    }
}